package cn.tonystack.config;

import cn.tonystack.service.weixin.IWeixinApiService;
import cn.tonystack.service.weixin.IWeixinMapService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;

/**
 * @description： 微信请求接口统一配置
 * @author： tony.pan  30.555605,114.206871
 * http://gc.ditu.aliyun.com/regeocoding?l="30.555605,114.206871"&type=010
 * @create： 2024/10/9 21:41
 */
@Slf4j
@Configuration
public class Retrofit2Config {

    private static final String BASE_URL= "https://api.weixin.qq.com/";

    private static final String MAP_URL = "https://apis.map.qq.com/";

    @Bean
    public Retrofit retrofit() {
        return new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(JacksonConverterFactory.create())
                .build();
    }

    @Bean("retrofitMap")
    public Retrofit retrofitMap() {
        return new Retrofit.Builder()
                .baseUrl(MAP_URL)
                .addConverterFactory(JacksonConverterFactory.create())
                .build();
    }

    @Bean
    public IWeixinApiService weixinApiService(Retrofit retrofit) {
        return retrofit.create(IWeixinApiService.class);
    }

    @Bean
    public IWeixinMapService weixinMapService(Retrofit retrofitMap) {
        return retrofitMap.create(IWeixinMapService.class);
    }

}
